package ModelLayer;
import java.util.HashSet;
import java.util.Iterator;

/**
 * Write a description of class LoanContainer here.
 * 
 * @author (group1) 
 * @version (2013.11.05)
 */
public class LoanContainer
{
    private HashSet<Loan> loans;
    private static DVDContainer dvdCont;
    private static LoanContainer instance;
    
    public LoanContainer()
    {
        loans = new HashSet<>();
        dvdCont = DVDContainer.getInstance();        
    }
    
    public static LoanContainer getInstance() {  if(instance==null)  instance = new LoanContainer();   return instance;  }
    
    
    public boolean changeState(long idP, long idD, String serialNo) { return dvdCont.changeState(idP, idD, serialNo); }
    
    public boolean addLoan(long idP, long idD, int daysToBorrow)
    { 
        Copy copy = dvdCont.availableCopy(idD);
        if(copy==null) return false;
        
        loans.add(new Loan(idD,idP,daysToBorrow,copy)); 
        
        return true;
    }
    
    public Iterator getLoans()  {  return loans.iterator(); }
    
    
    
    
    
}
